﻿<?php
// š
include_once('data.php');


if (isset($_GET['rev'])) {
	$mysqli = new mysqli(CONNECT_HOST, CONNECT_USER, CONNECT_PASS, CONNECT_DB);
	$mysqli->query("SET NAMES 'utf8'");

	$sql = "select stop_id, stop_name, latitude, longitude, zone, ondemand, active, stop_revision from stop where stop_revision > ".$_GET['rev'].";";
	$result = $mysqli->query($sql);
	if (mysqli_num_rows($result) != 0) {
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
		echo "<stoplist>\n";
		while ($row = $result->fetch_assoc()) {
			echo "\t<stop stop_id=\"" . $row["stop_id"] . "\">\n";
			echo "\t\t<stop_name>" . $row["stop_name"] . "</stop_name>\n";
			echo "\t\t<stop_latitude>" . $row["latitude"] . "</stop_latitude>\n";
			echo "\t\t<stop_longitude>" . $row["longitude"] . "</stop_longitude>\n";
			echo "\t\t<stop_zone>" . $row["zone"] . "</stop_zone>\n";
			echo "\t\t<stop_ondemand>" . $row["ondemand"] . "</stop_ondemand>\n";
			echo "\t\t<stop_active>" . $row["active"] . "</stop_active>\n";
			echo "\t\t<stop_revision>" . $row["stop_revision"] . "</stop_revision>\n";
			
			$sql = "SELECT stop_platform, latitude, longitude FROM stopplatforms WHERE stop_id = ".$row["stop_id"].";";
			$result1 = $mysqli->query($sql);
			if (mysqli_num_rows($result1) != 0) {
				echo "\t\t<platformlist>\n";
				while ($row1 = $result1->fetch_assoc()) {
					echo "\t\t\t<platform platform_id=\"" . $row1["stop_platform"] . "\">\n";
					echo "\t\t\t\t<platform_latitude>" . $row1["latitude"] . "</platform_latitude>\n";
					echo "\t\t\t\t<platform_longitude>" . $row1["longitude"] . "</platform_longitude>\n";
					echo "\t\t\t</platform>\n";
				}
				echo "\t\t</platformlist>\n";
			}
			echo "\t</stop>\n";
		}
		echo "</stoplist>";
	} else {
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<stoplist>\n</stoplist>";	
	}
	$mysqli->close();
} else {
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<stoplist>\n</stoplist>";	
}
?>